<!--
 * @Author: White
 * @description: 首页
 * @LastEditTime: 2021-08-17 19:36:53
-->

<template>
  <div class="me">
    <div class="list">
        <div class="list-wrap">
            <div class="list-item" v-for="(item, index) in listData" :key="index" @click="detail(item)">
                <div class="list-text">
                  <div class="list-author"><span>{{item.author}}</span></div>
                  <div class="list-title">{{item.title}}</div>
                  <div class="list-contnet">{{item.content}}</div>
                  <div class="list-time">{{$filters.timefilter("yyyy-MM-dd hh:mm:ss", item.time)}}</div>
                </div>
                <img v-if="item.cover" class="list-cover" :src="item.cover" alt="">
            </div>
        </div>
    </div>
  </div>
</template>

<script>
import { useRouter } from 'vue-router'
import { defineComponent, reactive, toRefs } from 'vue'
import { auth, app } from '@/api/clouldbase'
export default defineComponent({
  setup () {
    const router = useRouter()
    const list = reactive({
      listData: []
    })
    auth.anonymousAuthProvider().signIn().then(() => {
      console.log('登录成功')
      // 在登录成功的回调中连接数据库
      const db = app.database()
      db.collection('nav_content').get().then(res => {
        console.log(res.data)
        list.listData = res.data
        console.log(list.listData)
      })
    }).catch(err => {
      console.log(err)
    })
    const detail = (item) => {
      console.log(item)
      router.push({
        path: 'DetailArticle',
        query: { id: item._id }
      })
    }
    return {
      ...toRefs(list),
      detail
    }
  }
})
</script>

<style lang="scss" scoped>
.me {
  background-color: #f4f5f5;
  height: calc(100vh - 70px);
  ::-webkit-scrollbar {
  display: none; /* Chrome Safari */
  }
  .list {
    padding-top: 20px;
    .list-wrap {
      max-width: 1200px;
      overflow: scroll;
      margin: 0 auto;
      .list-item {
        width: 100%;
        height: 130px;
        background-color: #fff;
        padding: 10px 20px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        padding-bottom: 12px;
        border-bottom: 1px solid #e5e6eb;
        .list-text {
          flex-grow: 1;
          width: 70%;
          .list-author {
            font-size: 10px;
            margin-bottom: 10px;
            color: #909090;
          }
          .list-title {
            font-size: 20px;
            font-weight: 600;
            line-height: 1.2;
            color: #2e3135;
            margin-bottom: 8px;
          }
          .list-contnet {
            font-size: 16px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-bottom: 10px;
          }
          .list-time {
            font-size: 14px;
            color: #b2bac2;
          }
        }
        .list-cover {
          flex: 0 0 auto;
          width: 120px;
          height: 80px;
          margin-left: 24px;
          border-radius: 2px;
        }
      }
    }
  }
}
</style>
